#include <syscalls.h>
#include <ipc.h>


unsigned int fork()
{
	unsigned int ret;
	asm volatile ("int $0xFF" : "=a" (ret) : "0" (0x100));
	return ret;
}

void exit()
{
	unsigned int parent = getppid();
	signal(parent, SIG_QUIT);
	asm volatile ("int $0xFF" : : "a" (0x101));
}

void done()
{
	asm volatile ("int $0xFF" : : "a" (0x102));
}

void yield()
{
	asm volatile ("int $0xFF" : : "a" (0x106));
}

unsigned int getpid()
{
	unsigned int ret;
	asm volatile ("int $0xFF" : "=a" (ret) : "0" (0x103));
	return ret;
}

unsigned int getppid()
{
	unsigned int ret;
	asm volatile ("int $0xFF" : "=a" (ret) : "0" (0x104));
	return ret;
}

void regirq(unsigned int irq)
{
	asm volatile ("int $0xFF" : : "a" (0x107), "b" (irq));
}

void putch(unsigned char c)
{
	asm volatile ("int $0xFF" : : "a" (0xF00), "b" ((unsigned int)c));
}

void puts(unsigned char *c)
{
	while(*c != '\0')
	{
		putch(c[0]);
		c++;
	}
}

void signal(unsigned int process, unsigned int signum)
{
	asm volatile ("int $0xFF" : : "a" (0x105), "b" (process), "c" (signum));
}

void map(unsigned int virtual, unsigned int flags)
{
	asm volatile ("int $0xFF" : : "a" (0x500), "b" (virtual), "c" (flags));
}

void unmap(unsigned int virtual)
{
	asm volatile ("int $0xFF" : : "a" (0x501), "b" (virtual));
}

void setmap(unsigned int virtual, unsigned int physical, unsigned int flags)
{
	asm volatile ("int $0xFF" : : "a" (0x502), "b" (virtual), "c" (physical), "d" (flags));
}

void exec(unsigned int virtual, unsigned int args)
{
	asm volatile ("int $0xFF" : : "a" (0x108), "b" (virtual), "c" (args));
}

void setmsg(unsigned int virtual)
{
	asm volatile ("int $0xFF" : : "a" (0x109), "b" (virtual));
}
void getmsg(unsigned int virtual)
{
	asm volatile ("int $0xFF" : : "a" (0x10A), "b" (virtual));
}

unsigned int v86int(unsigned int interrupt, void *registers)
{
	unsigned int i;
	asm volatile ("int $0xFF" : "=a" (i) : "0" (0x400), "b" (interrupt), "c" (registers));
	return i;
}

unsigned int *v86_buffer()
{
	unsigned int *buffer;
	asm volatile ("int $0xFF" : "=a" (buffer) : "0" (0x401));
	return buffer;
}

